package org.springleaf.ui;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

@SuppressWarnings("unchecked")
public abstract class AbstractTag extends TagSupport {

	private static final long serialVersionUID = 1L;

	protected HttpServletRequest getReq() {
		return (HttpServletRequest) pageContext.getRequest();
	}

	protected HttpServletResponse getResp() {
		return (HttpServletResponse) pageContext.getResponse();
	}

	protected HttpSession getSess() {
		return pageContext.getSession();
	}

	protected HttpSession setSessAttr(String name, String value) {
		HttpSession sess = getSess();
		sess.setAttribute(name, value);
		return sess;
	}

	protected <T> T getSessAttr(String name) {
		return (T) getSess().getAttribute(name);
	}

	protected <T> T getAttr(String name) {
		return (T) getReq().getAttribute(name);
	}

	protected String getParam(String name) {
		return getReq().getParameter(name);
	}

	protected String[] getParams(String name) {
		return getReq().getParameterValues(name);
	}

	protected JspWriter getOut() {
		return pageContext.getOut();
	}

}
